<?php


define('ACCESS_KEY9296',true);
require('./include/init.php');

$mysql = mysql::getIns();

if(isset($_GET['id'])&&!empty($_GET['id'])){
    $res = $mysql->query("SELECT cake_class FROM cake");
    $a = 0;
    while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
     $cake_class[$a]=$row['cake_class'];
     $a++;
 }
 var_dump($cake_class);
 $class = (empty($_GET["id"])||!in_array($_GET["id"],$cake_class)||floor($_GET["id"])===$_GET["id"])?'01':$_GET["id"];
 var_dump($class);
}
$allNum = allNews();
$pageSize = 6;
$endPage = ceil($allNum/$pageSize);
$pageNum = (empty($_GET["page"])||$_GET["page"]>$endPage||floor($_GET["page"])===$_GET["page"])?1:$_GET["page"];
echo $pageNum;
echo $endPage;
if(empty($class)){
    $cake = pages($pageNum,$pageSize);
    //echo '0000000';
}else{
    $cake = pages($pageNum,$pageSize,$class);
    //echo '1111111';
}
$a = 0;
foreach ($cake as $value) {
    //var_dump($value);
    $id[$a]=$value['cake_id'];
    $img[$a]=$value['cake_images'];
    $price[$a]=$value['cake_price'];
    $a++;
}

include(ROOT.'view/shop/header.html');
include(ROOT.'view/shop/products.html');
include(ROOT.'view/shop/footer.html');